package com.alipay.controller;

import com.alipay.model.dto.Request;
import com.alipay.model.dto.Response;
import com.alipay.service.TransferAccountsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.UUID;

/**
 *
 * @author Jun
 * @date 2019/3/22
 */
@Slf4j
@RestController
@RequestMapping(value = "/trans")
public class TransController {

    @Autowired
    private TransferAccountsService transferAccountsService;

    /**
     * 交易请求
     * @param request
     * @return
     */
    @PostMapping("")
    public Response trans(@RequestBody @Valid Request request){
        if (StringUtils.isBlank(request.getRequestId())){
            request.setRequestId(UUID.randomUUID().toString().replace("-",""));
        }
        return transferAccountsService.transferAccounts(request);
    }
}
